// 导入axios工具包
import instance from '@/utils/axios.js'

// 1.获取所有频道列表
function getChannelList(){
    return instance ({
        url:'/v1_0/channels',
        method:'get'
    })
}

// 2.请求文章列表数据
function getArticleList({channel_id,timestamp}){
    return instance({
        url:'/v1_0/articles',
        method:'GET',
        params:{
            channel_id,
            timestamp,
            with_top:1
        }
    })
}

// 3.获取文章详情
function getArticleInfo(id){
    return instance({
        url:`/v1_0/articles/${id}`,
        method:'get'
    })
}

// 4.关注用户 与  取消关注
// 4.1关注
function followingUser(id){
    return instance({
        url:'/v1_0/user/followings',
        method:'post',
        data:{ target : id }
    })
}

// 4.2取消关注
function unFollowingUser(id){
    return instance({
        url:`/v1_0/user/followings/${id}`,
        method:'delete'
    })
}

// 5.点赞 与  取消点赞
// 5.1点赞
function praiseUser(id){
    return instance({
        url:'/v1_0/article/likings',
        method:'post',
        data:{ target : id }
    })
}

// 5.2取消点赞
function unPraiseUser(id){
    return instance({
        url:`/v1_0/article/likings/${id}`,
        method:'delete'
    })
}

// 6.不喜欢 与  取消不喜欢
// 6.1不喜欢
function dislike(id){
    return instance({
        url:'/v1_0/article/dislikes',
        method:'post',
        data:{ target : id }
    })
}

// 6.2取消不喜欢
function unDislike(id){
    return instance({
        url:`/v1_0/article/dislikes/${id}`,
        method:'delete'
    })
}

// 7.推荐词列表
function getSuggestionList(q){
    return instance({
        url:'/v1_0/suggestion',
        method:'get',
        params:{q}
    })
   
}

// 8.搜索结果
function getSearchList({page,per_page,q}){
    return instance({
        url:'/v1_0/search',
        method:'get',
        params:{page,
            per_page,
            q
        }
    })
}


// 导出接口
export {getChannelList,
    getArticleList,
    getArticleInfo,
    followingUser,
    unFollowingUser,
    praiseUser,
    unPraiseUser,
    dislike,
    unDislike,
    getSuggestionList,
    getSearchList
}
